<?php
/**
 * Created by PhpStorm.
 * User: yaoihu
 * Date: 2019/6/16
 * Time: 20:57
 */

namespace Shop\Http\Controllers;


use App\Helpers\SelfResponse;
use App\Helpers\Uploader\UploadImage;
use function Couchbase\defaultDecoder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use OSS\Core\OssException;
use OSS\OssClient;

class UploadController extends BaseController
{
    public function uploadBase64(Request $request)
    {
        $config = config('UEditorUpload.upload');
        $upConfig = array(
            "pathFormat" => $config['imagePathFormat'],
            "maxSize" => $config['imageMaxSize'],
            "allowFiles" => $config['imageAllowFiles'],
            'fieldName' => $request->input('imgField',$config['imageFieldName']),
            'imageGroup'=>$request->input('group','image')
        );

        $res = with(new UploadImage($upConfig,$request))->uploadBase64($request);
        if($res['status'] == 1){
            return SelfResponse::success('上传成功','',['url'=>$res['url']]);
        }

        return SelfResponse::error($res['msg']);
    }
}